cmake_minimum_required(VERSION 3.20)

# 这里修改为你的项目名称
project(funcPlot)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 这里修改为 你的qt 前缀
set(CMAKE_PREFIX_PATH "D:/Software/SDK/Qt/5.15.2/mingw81_64")
# 这里设置 qt大的版本号
set(QTVersion 5)


# 这里修改为你的qt版本
# 同时添加你的需要的qt依赖
find_package(Qt${QTVersion}
        COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED
        )

# 这里添加 头文件目录
#include_directories()


# 这里添加源码文件
set(SRCS
        src/main.cpp
        )
# 这里添加源码目录
set(SRC_DIRS
        src/MainWindow
        src/FuncDialog
        src/Painter
        src/FuncListModel
        src/Func
        )
# 寻找 源码文件
foreach(dir ${SRC_DIRS})
    set(tmp "")
    aux_source_directory(${dir} tmp)
    LIST(APPEND SRCS " ")
    LIST(APPEND SRCS ${tmp})
endforeach(dir)




# debug 模式带黑框 release不带
if(CMAKE_BUILD_TYPE MATCHES "Debug")
    message("Debug Build")
    add_executable(${PROJECT_NAME}   ${SRCS} )
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
    message("Release Build")
    add_executable(${PROJECT_NAME} WIN32 ${SRCS})
endif()


# 添加你需要连接的库
target_link_libraries(${PROJECT_NAME}
        Qt::Core
        Qt::Gui
        Qt::Widgets
        )

set(QT_LIB_LIST
        Core Gui Widgets  Test
        )


# 针对windows 平台复制 dll 到 build 目录下
if (WIN32)
    set(DEBUG_SUFFIX)
    # 这里取消 debug版本的dll 需要自行添加
#    if (CMAKE_BUILD_TYPE MATCHES "Debug")
#        set(DEBUG_SUFFIX "d")
#    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    #拷贝 style 文件
    if(EXISTS "${QT_INSTALL_PATH}/plugins/styles/qwindowsvistastyle.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/styles/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/styles/qwindowsvistastyle.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/styles/")
    endif()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB ${QT_LIB_LIST})
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt${QTVersion}${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()
